/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model.creature.plant.plugin;

import java.awt.Image;
import model.creature.plant.AOEAttackerPlant;
import model.game.GameInterface;
import model.item.Item;
import model.map.cell.PlantableCell;
import model.utility.ImageUtility;

/**
 * a long-living plant that smashes anyone nearby
 *
 * Attacks every two turns. Grows in 3 days.
 *
 * Can be harvested but dies afterward.
 */
public class Wintermelon extends AOEAttackerPlant {

  public Wintermelon(GameInterface game, PlantableCell cell) {
    super(game, cell);
  }

  /**
   * Retrieves the fruit name from this plant when harvested
   */
  @Override
  protected String getFruitName() {
    return "Wintermelon";
  }

  /**
   * Retrieves the days required to go from seed to mature
   */
  @Override
  protected int timeToMature() {
    return 2;
  }

  /**
   * Retrieves the days before this plant dies
   */
  @Override
  protected int timeToDie() {
    return 100;
  }

  /**
   * Retrieves the days before this plant can be harvested from mature state,
   * having beeing harvested harvest_count times before
   */
  @Override
  protected int timeToHarvest(int harvest_count) {
    return 1;
  }

  /**
   * Retrieves the HP of this plant at the given level
   * level can be accessed through getLevel()
   */
  @Override
  protected int getHPAtCurrentLevel() {
    return 80;
  }

  /**
   * Returns true iff plant can be upgraded again now
   * It's current level is given in getLevel()
   */
  @Override
  public boolean canUpgrade() {
    if (getLevel() < 3) return true;
    return false;
  }

  /**
   * Retrieves the price to upgrade this plant's level
   * It's current level is given in getLevel()
   * @requires canUpgrade()
   */
  @Override
  public int getUpgradeCost() {
    return getLevel() * 70 + 140;
  }

   /**
   * Returns the image sprite of this plant
   */
  @Override
  public Image getImage() {
    if (is_seed_) {
      return ImageUtility.loadImage("resources/pictures/plants/wintermelon/seed.png");
    } else if (isHarvestable()) {
      return ImageUtility.loadImage("resources/pictures/plants/wintermelon/harvestable.png");
    } else {
      return ImageUtility.loadImage("resources/pictures/plants/wintermelon/mature.png");
    }
  }

  /**
   * Returns the name of this plant
   * Primary Key
   */
  @Override
  public String getName() {
    return "Wintermelon";
  }

  /**
   * Return the season only during this season this plant may grow
   */
  @Override
  public String getSeason() {
    return "Winter";
  }

  /**
   * Returns the description of this plant
   */
  @Override
  public String getDescription() {
    return "Smashes anyone nearby for " + getPower() + " damage. Also somewhat"
            + " durable. Long-living. Slow attacker. Grows in winter. Bears"
            + " a fruit that sells for 220.";
  }

  /**
   * Determines the dmaage done by a creature when attacking
   */
  @Override
  public int getPower() {
    return 150 + 75 * getLevel();
  }

  /**
   * Returns the radius of this plant's attacks
   *
   * I.e., this plant attack at most plantAttackCount() monsters whose
   * manhattan distance with this plant is less than or equal getRadius()
   */
  public int getRadius() {
    return 1;
  }

  /**
   * Returns the number of shots this plant performs each time.
   */
  public int getAttackCount() {
    return 1;
  }

  @Override
  public int getAttackSpeed() {
    return 2;
  }

  @Override
  public Item harvest() {
    assert isHarvestable();
    Item harvest_result =
            game_.getItemManager().constructItemFromName(getFruitName());
    game_.getCreatures().getPlants().removePlant(this);
    return harvest_result;
  }

}
